/*
 *		This Code Was Created By Jeff Molofee 2000
 *		A HUGE Thanks To Fredric Echols For Cleaning Up
 *		And Optimizing The Base Code, Making It More Flexible!
 *		If You've Found This Code Useful, Please Let Me Know.
 *		Visit My Site At nehe.gamedev.net
 */

/*This horse race game, the ultimate in 3D entertainment, was made by:
              ...drumroll   ...ERIC NORTON!
			  norton@umr.edu	web.umr.edu/~norton  (until May 2003)
Basicly I started with tutorial 6 and gutted it and put in my stuff.  I threw
in the Font stuff from tutorial 13.  Feel free to change anything or use my
Deck class for your own games.  Probably there's better Deck classes out there
but I couldn't find any and I felt like making my own.*/

/*This game plays fine on a GeForce 4 Ti4200.  It runs ungodly slow on campus computers.
They're P4's with 512MB RAM so it must be the video card I think.  I don't how good
a video card you need.  Maybe replace the front of the bored with one bitmap and quad
instead of 50 quads and discs.*/

/*suggestions for improvement:
1 - Better card bitmaps.
2 - Better sounds. (find a cardsound.wav for me)
3 - Make the controls and messages better.  As an option to the spacebar and +/- buttons
	I was going to add a 'GO' button to click and use the scroll button on the mouse, making
	the game independent from the keyboard. I got bored of it though. 
4 - get rid of that damn point.cpp, I don't know how
5 - if no one else does this stuff I'll probably do it someday, and finish commenting it*/

#include <windows.h>		//Header File For Windows
#include <stdio.h>			//Header File For Standard Input/Output
#include <gl\gl.h>			//Header File For The OpenGL32 Library
#include <gl\glu.h>			//Header File For The GLu32 Library
#include <gl\glaux.h>		//Header File For The Glaux Library
#include <sys/timeb.h>		//for that Time() function
#include <math.h>			//for math...
#include "deck.h"			//include my versatile deck Deck class

//this is a golfpeg, pretend it's a horse
struct Horse
{
	int ispot;
	float rgfcolor[3];
};

bool btrash=false;	//beats me

Horse racehorses[11];	//11 horses
Deck horsedeck;			//the deck of cards, I took out the A and K
bool bcursor=true;		//I forgot

//I don't know the constants for all of the keys
const int IPLUS=107;
const int IMINUS=109;

/**bools for menus**/
bool bmenu=false;	//display main menu
bool bstats=false;	//stat menu (if I ever make it)
int inewgame=0;		//the single most important variable in this code
int ifaq=0;			//menu
bool bflip=false;	//I forgot
bool breset=false;	//are you sure you want to reset?
bool bdark=false;	//darken game for menus
bool bnickel=false;	//display players' nickels
bool bdice=true;	//for when the dice start rolling

//if you try to increase IMAXPLAYERS you'll have to be creative.  To fit more than
//20 players on the screen I'd shift one set of 20 off the screen and display the other
//20.  Maybe you have a better idea, I don't know
const int IMAXPLAYERS=20;
char rgcnames[IMAXPLAYERS][4];	//stores three-letter names of IMAXPLAYERS players
int rginickels[IMAXPLAYERS];	//stores number of nickels each player has
int ipot=0;						//stores number of nickels in the pot
char ctrash;					//multi-purpose char
int itrash;						//counter, don't mess with unless you understand it
int inames;						//counter, "	
int iinitial;					//counter, "
int iintro=0;					//counter for my logo at the beginning
//these time one second intervals, probably there was a smarter way to do it
int isec, isec2;
int icash=1;					//user specified starting money
int iguy=0;						//counter, "
int irand1, irand2;				//store dice rolls
float fcardzoom=0.0f;			//zooms the player's cards
int rgistorespot[2];			//these two store where the bad cards are
int rgistorenum[4];
bool bstore=false;				//take turns finding bad cards and paying for them

int iplayers=6;					//user specified number of players
int ihuman=1;					//user specified number of human players
bool bplus=false;				//is '+' key being pressed?
bool bminus=false;				//guess
bool bspace=false;
bool bready=true;				//i forgot, probably important
bool bF12=false;				//is F12 being pressed?
bool bF11=false;
bool bF8=false;
bool bF6=false;
bool bF5=false;
bool bplayer=false;				//are we waiting for a player to click 'OK'?
const int IINTRO=7;				//play my logo for this many loops
const int ICREDITS=1400;		//play credits loop this many times  (these aren't really loops)
int icredits=ICREDITS;			//play credits at end of game
const float	FCREDITS=-0.6f;		//start them off screen
float fcredits=FCREDITS;		//move the credits up
bool bwin;						//for after a horse wins
bool bturbo=false;				//yeah!
bool bdone=false;				//probably unnecessary, didn't feel like messing with 'done'
int iturn=0;					//who goes first?

//from Smart Idiot's 3D dragging demo
float distance;        // Where in the depth buffer the object is.
double x_offset = 0;   // Add this to the box when position and all the box is where it should be.
double y_offset = 0;   // and yes, they need to be DOUBLE and NOT FLOAT!!!
double z_offset = 0;

GLuint	base;

//nehe stuff, I don't know what it means
HDC			hDC=NULL;		// Private GDI Device Context
HGLRC		hRC=NULL;		// Permanent Rendering Context
HWND		hWnd=NULL;		// Holds Our Window Handle
HINSTANCE	hInstance;		// Holds The Instance Of The Application

bool	keys[256];			// Array Used For The Keyboard Routine
bool	active=TRUE;		// Window Active Flag Set To TRUE By Default
bool	fullscreen=TRUE;	// Fullscreen Flag Set To Fullscreen Mode By Default

const int IPGDN=34;
GLfloat	xrot=0.0f;				// gameboard rotation
GLfloat	yrot=0.0f;				// gameboard rotation
GLfloat	zrot=0.0f;				// guess

GLfloat diexrot=0.0f;		//spin the dice, it's cool looking
GLfloat dieyrot=0.0f;
GLfloat diezrot=0.0f;
GLfloat diexrot2=0.0f;
GLfloat dieyrot2=0.0f;
GLfloat diezrot2=0.0f;
GLfloat erot=180.0f;

const float FXSPIN=3.0f;	//change these
const float FYSPIN=2.0f;
const float FZSPIN=3.0f;
float fxspin=FXSPIN;		//duh
float fyspin=FYSPIN;
float fzspin=FZSPIN;
int idice=0;				//I forgot
bool bspin=false;

//for holes and golf tees - check out the quadratics tutorial; I did
GLUquadricObj* quadratic;
//the bigger this is, the slower the drawing
const int ISLICE=16;
//tee (horse) dimensions
const float FRADIUS=0.09375f;
const float FHEIGHT=1.2f;

int ix, ij;		//multi-purpose counters
int itack;		//multi-purpose int
float fsparc;	//multi-purpose floats
float fsparc2;
float fx;		//this is a float
int loop;		//this is an int
//increase this if you add a texture, and make sure I did everything correctly there,
//there was some guess work going on there
const int ITEX=70;
GLuint	texture[ITEX];			// Storage For ITEX Textures

LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	// Declaration For WndProc

//close all the menus
void Falsify()
{
	bmenu=false;
	bstats=false;
	ifaq=0;
	bready=true;
	breset=false;
	bdark=false;
}

//this function explains itself
void ResetNames()
{
	for(ix=0;ix<IMAXPLAYERS;ix++)
	{
		rgcnames[ix][0]='A';
		rgcnames[ix][1]='A';
		rgcnames[ix][2]='A';
		rgcnames[ix][3]='\0';
	}
}

//pass this a data type Card and it loads up the right texture
void LoadCard(Card dummy)
{
	dummy.inum*=4;
	if(dummy.csuit==CHEART)
		dummy.inum-=1;
	else if(dummy.csuit==CDIAMOND)
		dummy.inum-=2;
	else if(dummy.csuit==CCLUB)
		dummy.inum-=3;
	glBindTexture(GL_TEXTURE_2D, texture[dummy.inum]);
}

//for dice rolls
int RandomSix()
{
	int inum;
	
	do
	{
		inum=((6*rand())/RAND_MAX)+1;
	}while(inum<1||inum>6);

	return inum;
}

//milliseconds of time of day is returned
int Time()
{
	struct _timeb timebuffer;	//records time

	if(!bturbo)
	{
		_ftime(&timebuffer);		//getting time
		return timebuffer.millitm;	//returning milliseconds
	}
	else if(isec+901>1000)
	{
		return isec-99;
	}
	else
	{
		return isec+901;
	}
}

void StopDice()
{
	bspin=false;
	irand1=RandomSix();
	irand2=RandomSix();
	fxspin=0.0f;
	fyspin=0.0f;
	fzspin=0.0f;
	PlaySound("Data/dice2.wav", NULL, SND_ASYNC);
	//fix diexrot, etc. to actual side with number.
	switch(irand1)
	{
	case 1:
		diexrot=0.0f;
		dieyrot=0.0f;
		diezrot=0.0f;
		break;
	case 2:
		diexrot=0.0f;
		dieyrot=90.0f;
		diezrot=0.0f;
		break;
	case 3:
		diexrot=90.0f;
		dieyrot=0.0f;
		diezrot=0.0f;
		break;
	case 4:
		diexrot=-90.0f;
		dieyrot=0.0f;
		diezrot=0.0f;
		break;
	case 5:
		diexrot=0.0f;
		dieyrot=-90.0f;
		diezrot=0.0f;
		break;
	case 6:
		diexrot=0.0f;
		dieyrot=-180.0f;
		diezrot=0.0f;
		break;
	default:
		//uh...
		break;
	}
	switch(irand2)
	{
	case 1:
		dieyrot2=0.0f;
		diezrot2=0.0f;
		diexrot2=0.0f;
		break;
	case 2:
		dieyrot2=0.0f;
		diezrot2=90.0f;
		diexrot2=0.0f;
		break;
	case 3:
		dieyrot2=90.0f;
		diezrot2=0.0f;
		diexrot2=0.0f;
		break;
	case 4:
		dieyrot2=-90.0f;
		diezrot2=0.0f;
		diexrot2=0.0f;
		break;
	case 5:
		dieyrot2=0.0f;
		diezrot2=-90.0f;
		diexrot2=0.0f;
		break;
	case 6:
		dieyrot2=0.0f;
		diezrot2=-180.0f;
		diexrot2=0.0f;
		break;
	default:
		//uh...
		break;
	}
	idice+=1;
	isec=Time();
}

//******next three functions from tutorial 13***********/
GLvoid BuildFont(GLvoid)								// Build Our Bitmap Font
{
	HFONT	font;										// Windows Font ID
	HFONT	oldfont;									// Used For Good House Keeping

	base = glGenLists(96);								// Storage For 96 Characters

	font = CreateFont(	-24,							// Height Of Font
						0,								// Width Of Font
						0,								// Angle Of Escapement
						0,								// Orientation Angle
						FW_BOLD,						// Font Weight
						FALSE,							// Italic
						FALSE,							// Underline
						FALSE,							// Strikeout
						ANSI_CHARSET,					// Character Set Identifier
						OUT_TT_PRECIS,					// Output Precision
						CLIP_DEFAULT_PRECIS,			// Clipping Precision
						ANTIALIASED_QUALITY,			// Output Quality
						FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch
						"Courier New");					// Font Name

	oldfont = (HFONT)SelectObject(hDC, font);           // Selects The Font We Want
	wglUseFontBitmaps(hDC, 32, 96, base);				// Builds 96 Characters Starting At Character 32
	SelectObject(hDC, oldfont);							// Selects The Font We Want
	DeleteObject(font);									// Delete The Font
}

GLvoid KillFont(GLvoid)									// Delete The Font List
{
	glDeleteLists(base, 96);							// Delete All 96 Characters
}

GLvoid glPrint(const char *fmt, ...)					// Custom GL "Print" Routine
{
	char		text[256];								// Holds Our String
	va_list		ap;										// Pointer To List Of Arguments

	if (fmt == NULL)									// If There's No Text
		return;											// Do Nothing

	va_start(ap, fmt);									// Parses The String For Variables
	    vsprintf(text, fmt, ap);						// And Converts Symbols To Actual Numbers
	va_end(ap);											// Results Are Stored In Text

	glPushAttrib(GL_LIST_BIT);							// Pushes The Display List Bits
	glListBase(base - 32);								// Sets The Base Character to 32
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	// Draws The Display List Text
	glPopAttrib();										// Pops The Display List Bits
}
/************************************************/

/******nehe stuff***********/
AUX_RGBImageRec *LoadBMP(char *Filename)				// Loads A Bitmap Image
{
	FILE *File=NULL;									// File Handle

	if (!Filename)										// Make Sure A Filename Was Given
	{
		return NULL;									// If Not Return NULL
	}

	File=fopen(Filename,"r");							// Check To See If The File Exists

	if (File)											// Does The File Exist?
	{
		fclose(File);									// Close The Handle
		return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer
	}

	return NULL;										// If Load Failed Return NULL
}

int LoadGLTextures()									// Load Bitmaps And Convert To Textures
{
	int Status=FALSE;						// Status Indicator
	AUX_RGBImageRec *TextureImage[ITEX];				// Create Storage Space For The Texture Data
	memset(TextureImage,0,sizeof(void *)*ITEX);			// Set The Pointer To NULL

	//I added a kabillion textures here.
	//You want a rough night?  Try stretching and shrinking
	//52 card bitmaps until they're square and have dimensions
	//a power of 2.
	if ((TextureImage[0]=LoadBMP("Data/b.bmp")) &&		
	    (TextureImage[1]=LoadBMP("Data/ac.bmp")) &&	
	    (TextureImage[2]=LoadBMP("Data/ad.bmp")) &&	
	    (TextureImage[3]=LoadBMP("Data/ah.bmp")) &&	
		(TextureImage[4]=LoadBMP("Data/as.bmp")) &&	
	    (TextureImage[5]=LoadBMP("Data/2c.bmp")) &&	
	    (TextureImage[6]=LoadBMP("Data/2d.bmp")) &&	
		(TextureImage[7]=LoadBMP("Data/2h.bmp")) &&	
	    (TextureImage[8]=LoadBMP("Data/2s.bmp")) &&	
	    (TextureImage[9]=LoadBMP("Data/3c.bmp")) &&	
		(TextureImage[10]=LoadBMP("Data/3d.bmp")) &&	
	    (TextureImage[11]=LoadBMP("Data/3h.bmp")) &&	
	    (TextureImage[12]=LoadBMP("Data/3s.bmp")) &&	
		(TextureImage[13]=LoadBMP("Data/4c.bmp")) &&	
	    (TextureImage[14]=LoadBMP("Data/4d.bmp")) &&	
	    (TextureImage[15]=LoadBMP("Data/4h.bmp")) &&	
		(TextureImage[16]=LoadBMP("Data/4s.bmp")) &&	
	    (TextureImage[17]=LoadBMP("Data/5c.bmp")) &&	
	    (TextureImage[18]=LoadBMP("Data/5d.bmp")) &&	
		(TextureImage[19]=LoadBMP("Data/5h.bmp")) &&	
	    (TextureImage[20]=LoadBMP("Data/5s.bmp")) &&	
	    (TextureImage[21]=LoadBMP("Data/6c.bmp")) &&	
		(TextureImage[22]=LoadBMP("Data/6d.bmp")) &&	
	    (TextureImage[23]=LoadBMP("Data/6h.bmp")) &&	
	    (TextureImage[24]=LoadBMP("Data/6s.bmp")) &&	
		(TextureImage[25]=LoadBMP("Data/7c.bmp")) &&	
	    (TextureImage[26]=LoadBMP("Data/7d.bmp")) &&	
	    (TextureImage[27]=LoadBMP("Data/7h.bmp")) &&	
		(TextureImage[28]=LoadBMP("Data/7s.bmp")) &&	
	    (TextureImage[29]=LoadBMP("Data/8c.bmp")) &&	
	    (TextureImage[30]=LoadBMP("Data/8d.bmp")) &&	
		(TextureImage[31]=LoadBMP("Data/8h.bmp")) &&	
	    (TextureImage[32]=LoadBMP("Data/8s.bmp")) &&	
	    (TextureImage[33]=LoadBMP("Data/9c.bmp")) &&	
		(TextureImage[34]=LoadBMP("Data/9d.bmp")) &&	
	    (TextureImage[35]=LoadBMP("Data/9h.bmp")) &&	
	    (TextureImage[36]=LoadBMP("Data/9s.bmp")) &&	
		(TextureImage[37]=LoadBMP("Data/tc.bmp")) &&	
	    (TextureImage[38]=LoadBMP("Data/td.bmp")) &&	
	    (TextureImage[39]=LoadBMP("Data/th.bmp")) &&	
		(TextureImage[40]=LoadBMP("Data/ts.bmp")) &&	
	    (TextureImage[41]=LoadBMP("Data/jc.bmp")) &&	
	    (TextureImage[42]=LoadBMP("Data/jd.bmp")) &&	
		(TextureImage[43]=LoadBMP("Data/jh.bmp")) &&	
	    (TextureImage[44]=LoadBMP("Data/js.bmp")) &&	
	    (TextureImage[45]=LoadBMP("Data/qc.bmp")) &&	
		(TextureImage[46]=LoadBMP("Data/qd.bmp")) &&	
	    (TextureImage[47]=LoadBMP("Data/qh.bmp")) &&	
	    (TextureImage[48]=LoadBMP("Data/qs.bmp")) &&	
		(TextureImage[49]=LoadBMP("Data/kc.bmp")) &&	
	    (TextureImage[50]=LoadBMP("Data/kd.bmp")) &&	
	    (TextureImage[51]=LoadBMP("Data/kh.bmp")) &&	
		(TextureImage[52]=LoadBMP("Data/ks.bmp")) &&	
		(TextureImage[53]=LoadBMP("Data/Font.bmp")) &&
		(TextureImage[54]=LoadBMP("Data/pointer.bmp")) &&
		(TextureImage[55]=LoadBMP("Data/pointerblack.bmp")) &&
		(TextureImage[56]=LoadBMP("Data/button.bmp")) &&
		(TextureImage[57]=LoadBMP("Data/NeHe.bmp")) &&
		(TextureImage[58]=LoadBMP("Data/peg.bmp")) &&
		(TextureImage[59]=LoadBMP("Data/cardside.bmp")) &&
	    (TextureImage[60]=LoadBMP("Data/NeHe2.bmp")) &&
		(TextureImage[61]=LoadBMP("Data/faq.bmp")) &&
		(TextureImage[62]=LoadBMP("Data/die1.bmp")) &&
		(TextureImage[63]=LoadBMP("Data/die2.bmp")) &&
		(TextureImage[64]=LoadBMP("Data/die3.bmp")) &&
		(TextureImage[65]=LoadBMP("Data/die4.bmp")) &&
	    (TextureImage[66]=LoadBMP("Data/die5.bmp")) &&
		(TextureImage[67]=LoadBMP("Data/die6.bmp")) &&
		(TextureImage[68]=LoadBMP("Data/bean.bmp")) &&
		(TextureImage[69]=LoadBMP("Data/history.bmp")))

	{
		Status=TRUE;						// Set The Status To TRUE
		glGenTextures(ITEX, &texture[0]);				// Create Five Textures

		for (loop=0; loop<ITEX; loop++)				// Loop Through All ITEX Textures EN
		{
			glBindTexture(GL_TEXTURE_2D, texture[loop]);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY,
				0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
		}
	}
	//if you're good at this stuff make sure I did everything around here right EN
	for (loop=0; loop<ITEX; loop++)					// Loop Through All ITEX Textures EN
	{
		if (TextureImage[loop])					// If Texture Exists
		{
			if (TextureImage[loop]->data)			// If Texture Image Exists
			{
				free(TextureImage[loop]->data);		// Free The Texture Image Memory
			}
			free(TextureImage[loop]);			// Free The Image Structure
		}
	}
	return Status;							// Return The Status
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)		// Resize And Initialize The GL Window
{
	if (height==0)										// Prevent A Divide By Zero By
	{
		height=1;										// Making Height Equal One
	}

	glViewport(0,0,width,height);						// Reset The Current Viewport

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glLoadIdentity();									// Reset The Projection Matrix

	// Calculate The Aspect Ratio Of The Window
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glLoadIdentity();									// Reset The Modelview Matrix
}

int InitGL(GLvoid)										// All Setup For OpenGL Goes Here
{
	if (!LoadGLTextures())								// Jump To Texture Loading Routine ( NEW )
	{
		return FALSE;									// If Texture Didn't Load Return FALSE
	}

	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping ( NEW )
	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// Black Background
	glClearDepth(1.0f);									// Depth Buffer Setup
	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations

	//for quadratics
	quadratic=gluNewQuadric();			// Create A Pointer To The Quadric Object
	gluQuadricNormals(quadratic, GLU_SMOOTH);	// Create Smooth Normals
	gluQuadricTexture(quadratic, GL_TRUE);		// Create Texture Coords

	BuildFont();	//oops, don't forget this EN

	return TRUE;										// Initialization Went OK
}

/*******EN stuff**********/
//Random number 0=<fnum<=1
float Random()
{
	float fnum;
	
	do
	{
		fnum=((float)rand()/(float)RAND_MAX);
	}while(fnum<0||fnum>1);

	return fnum;
}

//pretty horses
void RandomHorse()
{
	for(ix=0;ix<11;ix++)
	{
		racehorses[ix].rgfcolor[0]=Random();
		racehorses[ix].rgfcolor[1]=Random();
		racehorses[ix].rgfcolor[2]=Random();
	}
}

int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The View

	if(iintro<IINTRO)
	{
		glDisable(GL_TEXTURE_2D);
		glTranslatef(-0.05f,0.05f,-1.0f);
		glRotatef(erot,0.0f,1.0f,0.0f);
		glColor3f(1.0f,0.0f,0.0f);
		glBegin(GL_QUADS);
			glColor3f(0.0f,1.0f,0.3f);	glVertex3f(-0.23f,-0.25f,0.05f);
			glColor3f(0.0f,0.3f,1.0f);	glVertex3f(0.12f,-0.25f,0.05f);
			glColor3f(0.0f,1.0f,0.3f);	glVertex3f(0.12f,0.25f,0.05f);
			glColor3f(0.0f,0.3f,1.0f);	glVertex3f(-0.23f,0.25f,0.05f);

			glColor3f(0.0f,0.3f,1.0f);	glVertex3f(-0.23f,-0.25f,-0.05f);
			glColor3f(0.0f,1.0f,0.3f);	glVertex3f(-0.23f,-0.25f,0.05f);
			glColor3f(0.0f,0.3f,1.0f);	glVertex3f(-0.23f,0.25f,0.05f);
			glColor3f(0.0f,1.0f,0.3f);	glVertex3f(-0.23f,0.25f,-0.05f);

			glColor3f(0.0f,0.3f,1.0f);	glVertex3f(-0.23f,-0.25f,-0.05f);
			glColor3f(0.0f,1.0f,0.3f);	glVertex3f(0.12f,-0.25f,-0.05f);
			glColor3f(0.0f,0.3f,1.0f);	glVertex3f(0.12f,0.25f,-0.05f);
			glColor3f(0.0f,1.0f,0.3f);	glVertex3f(-0.23f,0.25f,-0.05f);

			glColor3f(0.0f,0.0f,0.0f);
			glVertex3f(-0.12f,0.05f,0.06f);
			glVertex3f(0.12f,0.05f,0.06f);
			glVertex3f(0.12f,0.15f,0.06f);
			glVertex3f(-0.12f,0.15f,0.06f);

			glVertex3f(0.08f,-0.05f,0.06f);
			glVertex3f(0.12f,-0.05f,0.06f);
			glVertex3f(0.12f,0.05f,0.06f);
			glVertex3f(0.08f,0.05f,0.06f);

			glVertex3f(-0.12f,-0.15f,0.06f);
			glVertex3f(0.12f,-0.15f,0.06f);
			glVertex3f(0.12f,-0.05f,0.06f);
			glVertex3f(-0.12f,-0.05f,0.06f);
		glEnd();

		if(erot>0.0f)
		{
			erot-=2.0f;
			//erot-=0.5f;
		}
		else
		{
			glColor3f(0.0f,1.0f,0.3f);
			glRasterPos2f(0.14f,-0.26f);
			glPrint("SOFT");
			glColor3f(0.0f,0.3f,1.0f);
			glRasterPos2f(-0.23f,-0.29f);
			glPrint("A DIVISION OF ERIC NORTON INC.");
		}
	
		isec2=Time();
		if(isec2-isec>900||(isec2<isec&&1000-isec+isec2>900))
		{
			isec=Time();
			iintro+=1;
		}
	}
	else if(icredits<ICREDITS)
	{
		glDisable(GL_TEXTURE_2D);
		glTranslatef(0.0f,0.05f,-1.0f);
		glColor3f(0.0f,1.0f,0.0f);
		
		glRasterPos2f(-0.3f,fcredits);
		glPrint("EXECUTIVE PRODUCER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.06f);
		glPrint("PRODUCER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.12f);
		glPrint("ASSISTANT PRODUCER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.18f);
		glPrint("CREATIVE DIRECTOR:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.24f);
		glPrint("WRITER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.3f);
		glPrint("DESIGNER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.36f);
		glPrint("MODELER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.42f);
		glPrint("TEXTURE ARTIST:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.48f);
		glPrint("LEAD 3D ANIMATOR:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.54f);
		glPrint("3D ANIMATOR:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.6f);
		glPrint("ADDITIONAL ARTIST:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.66f);
		glPrint("LEAD PROGRAMMER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.72f);
		glPrint("TECHNOLOGY PROGRAMMER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.78f);
		glPrint("SOUND DESIGNER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.84f);
		glPrint("PUBLIC RELATIONS:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.9f);
		glPrint("SYSTEMS ADMINISTRATION:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-0.96f);
		glPrint("OFFICE MANAGER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.02f);
		glPrint("MARKETING DIRECTOR:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.08f);
		glPrint("MULTIMEDIA ENGINEER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.14f);
		glPrint("LOCALIZATION MANAGER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.2f);
		glPrint("LOCALIZATION COORDINATOR:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.26f);
		glPrint("SENIOR QA MANAGER:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.32f);
		glPrint("QUALITY ASSURANCE LEAD:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.38f);
		glPrint("ASSISTANT QUALITY ASSURANCE LEAD:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.44f);
		glPrint("QUALITY ASSURANCE TECHNICIAN:  ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.5f);
		glPrint("SPECIAL THANKS TO:  NEHE");
		glRasterPos2f(-0.3f,fcredits-1.53f);
		glPrint("                    http://nehe.gamedev.net");
		glRasterPos2f(-0.3f,fcredits-1.59f);
		glPrint("HORSE RACE GAME by: ERIC NORTON");
		glRasterPos2f(-0.3f,fcredits-1.62f);
		glPrint("                    http://web.umr.edu/~norton");
		glRasterPos2f(-0.3f,fcredits-1.65f);
		glPrint("                    norton@umr.edu");
		glRasterPos2f(-0.3f,fcredits-1.71f);
		glPrint("COMING SOON:  HORSE RACE II, THE REVENGE");

	
		isec2=Time();
		if(isec2-isec>10||(isec2<isec&&1000-isec+isec2>10))
		{
			isec=Time();
			icredits+=1;
			if(icredits==ICREDITS)
				bdone=true;
			fcredits+=0.002f;
		}
		if(keys[VK_F5]&&!bF5)
		{
			bdone=true;
		}
	}
	else	//everyting else
	{
	if(inewgame>0&&inewgame<5)
		bdark=true;
	/*****output all text*******/
	glDisable(GL_TEXTURE_2D);
	glTranslatef(0.0f,0.0f,-1.0f);						// Move One Unit Into The Screen
	glColor3f(1.0f,0.0f,0.0f);
	glRasterPos2f(-0.4f,0.30f);
	glPrint("MENU");	// Print GL Text To The Screen
	glRasterPos2f(-0.3f,0.30f);
	glPrint("STATS");	// Print GL Text To The Screen
	
	fsparc=0.04f;
	fsparc2=0.263f;
	if(inewgame>4&&!bnickel)
	{
		for(ix=0;ix<iplayers;ix++)
		{
			glRasterPos2f(fsparc,fsparc2);
			glPrint(rgcnames[ix]);
			if((ix+1)%5==0)
			{
				fsparc+=0.12f;
				fsparc2=0.263f;
			}
			else
			{
				fsparc2-=0.1f;
			}
		}
	}
	else if(inewgame>4)
	{
		glColor3f(Random(),Random(),Random());
		glRasterPos2f(0.04f,0.3f);
		glPrint("NICKELS");
		glColor3f(1.0f,0.0f,0.0f);
		for(ix=0;ix<iplayers;ix++)
		{
			glRasterPos2f(fsparc,fsparc2);
			glPrint("%i",rginickels[ix]);
			if((ix+1)%5==0)
			{
				fsparc+=0.12f;
				fsparc2=0.263f;
			}
			else
			{
				fsparc2-=0.1f;
			}
		}
	}
	glColor3f(1.0f,1.0f,0.0f);
	if(inewgame>4)
	{
		glRasterPos2f(0.18f,0.3f);
		glPrint("POT $%3.2f",float(ipot)/20.0f);
	}
	if(bplayer)
	{
		glRasterPos2f(0.22f,-0.295f);
		glPrint("OK");
	}
	if(bstore&&(inewgame<19||(inewgame==31&&itrash==0)))
	{
		glRasterPos2f(0.29f,-0.27f);
		glPrint("%s PAYS",rgcnames[rgistorespot[0]-5]);
		glRasterPos2f(0.29f,-0.32f);
		glPrint("%i NICKEL",itrash+1);
	}
	else if(bstore)
	{
		glRasterPos2f(0.27f,-0.27f);
		glPrint("%s PAYS",rgcnames[rgistorespot[0]-5]);
		glRasterPos2f(0.27f,-0.32f);
		glPrint("%i NICKELS",itrash+1);
	}
	if(bturbo)
	{
		glColor3f(0.0f,0.0f,1.0f);
		glRasterPos2f(0.37f,0.3f);
		glPrint("TURBO");
	}
	glColor3f(Random(),Random(),Random());
	if(bwin&&ipot/(41-inewgame)==1)
	{
		glRasterPos2f(0.29f,-0.27f);
		glPrint("%s WINS",rgcnames[rgistorespot[0]-5]);
		glRasterPos2f(0.29f,-0.32f);
		glPrint("1 NICKEL");
	}
	else if(bwin)
	{
		glRasterPos2f(0.29f,-0.27f);
		glPrint("%s WINS",rgcnames[rgistorespot[0]-5]);
		glRasterPos2f(0.29f,-0.32f);
		glPrint("%i NICKELS",ipot/(41-inewgame));
	}
	if(inewgame>31&&inewgame<37)
	{
		glRasterPos2f(0.2f,-0.3f);
		glPrint("HORSE %i WINS!!!",irand1+irand2);
	}
	if(inewgame>=31)
	{
		glRasterPos2f(0.03f,-0.3f);
		glPrint("%i",irand1+irand2);
	}
	glColor3f(1.0f,1.0f,0.0f);
	if(idice>0&&idice<3&&iguy<ihuman)
	{
		glRasterPos2f(0.2f,-0.3f);
		glPrint("%s, ROLL DICE",rgcnames[iguy]);
	}
	else if(idice>0&&!bstore)
	{
		glRasterPos2f(0.2f,-0.3f);
		glPrint("%s",rgcnames[iguy]);
	}

	//glEnable(GL_TEXTURE_2D);
	//glBindTexture(GL_TEXTURE_2D, texture[68]);
	if(bmenu)
	{
		glRasterPos2f(-0.4f,0.19f);
		glPrint("F1    - FULLSCREEN/WINDOWED");
		glRasterPos2f(-0.4f,0.16f);
		glPrint("F5    - QUIT PROGRAM (HIT TWICE TO SKIP CREDITS)");
		glRasterPos2f(-0.4f,0.13f);
		glPrint("ESC   - CLOSE MENUS");
		glRasterPos2f(-0.4f,0.10f);
		glPrint("SPACE - NEW GAME");
		glRasterPos2f(-0.4f,0.07f);
		glPrint("F11   - SHUFFLE (TRUST ME, IT SHUFFLES)");
		glRasterPos2f(-0.4f,0.04f);
		glPrint("F12   - RESET");
		glRasterPos2f(-0.4f,0.01f);
		glPrint("F3/F4 - ZOOM PLAYER'S CARDS");
		glRasterPos2f(-0.4f,-0.02f);
		glPrint("F9    - RANDOMIZE HORSE COLOR");
		glRasterPos2f(-0.4f,-0.05f);
		glPrint("F8    - SPEED NORMAL/TURBO");
		glRasterPos2f(-0.4f,-0.08f);
		glPrint("F6    - KEEP HITTING, SHOWS RULES AND FAQ");
		glRasterPos2f(-0.4f,-0.11f);
		glPrint("RIGHT-CLICK - SHOW PLAYER'S NICKELS");
		glRasterPos2f(-0.4f,-0.14f);
		glPrint("ARROW KEYS/DELETE/PGDN - MOVE BOARD");
	}
	else if(breset)
	{
		glRasterPos2f(-0.4f,0.19f);
		glPrint("ARE YOU SURE YOU WANT TO RESET?");
		glRasterPos2f(-0.4f,0.16f);
		glPrint("HIT F12 IF YOU'RE SURE");
	}
	else if(bstats)
	{
		glRasterPos2f(-0.4f,0.19f);
		glPrint("NOT PROGRAMMED YET...");
	}
	else if(ifaq==1)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texture[69]);
		glColor3f(1.0f,1.0f,1.0f);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.25f, 0.01f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.4f, -0.25f, 0.01f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.4f, 0.25f, 0.01f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.25f, 0.01f);
		glEnd();
		glDisable(GL_TEXTURE_2D);
	}
	else if(ifaq==2)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texture[61]);
		glColor3f(1.0f,1.0f,1.0f);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.4f, -0.25f, 0.01f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.4f, -0.25f, 0.01f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.4f, 0.25f, 0.01f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.4f, 0.25f, 0.01f);
		glEnd();
		glDisable(GL_TEXTURE_2D);
	}
	else if(inewgame==1)
	{
		glRasterPos2f(-0.4f,0.19f);
		glPrint("TOTAL NUMBER OF PLAYERS? [%i]",iplayers);
		glRasterPos2f(-0.4f,0.16f);
		glPrint("(USE +/- KEYS, HIT SPACE WHEN READY");
	}
	else if(inewgame==2)
	{
		glRasterPos2f(-0.4f,0.19f);
		glPrint("HOW MANY HUMAN PLAYERS? [%i] (OUT OF %i)", ihuman, iplayers);
		glRasterPos2f(-0.4f,0.16f);
		glPrint("(USE +/- KEYS, HIT SPACE WHEN READY");
	}
	else if(inewgame==3)
	{
		glRasterPos2f(-0.4f,0.19f);
		glPrint("PLAYER %i, ENTER THREE LETTER NAME", inames+1);
		glRasterPos2f(-0.4f,0.16f);
		glPrint("USE +/- KEYS, HIT SPACE TO CONTINUE");
		
		glRasterPos2f(-0.4f,0.13f);
		if(iinitial!=0)
			glColor3f(1.0f,1.0f,0.0f);
		else
			glColor3f(1.0f,0.0f,0.0f);
		glRasterPos2f(-0.4f,0.13f);
		glPrint("%c",rgcnames[inames][0]);

		if(iinitial!=1)
			glColor3f(1.0f,1.0f,0.0f);
		else
			glColor3f(1.0f,0.0f,0.0f);
		glRasterPos2f(-0.2f,0.13f);
		glPrint("%c",rgcnames[inames][1]);

		if(iinitial!=2)
			glColor3f(1.0f,1.0f,0.0f);
		else
			glColor3f(1.0f,0.0f,0.0f);
		glRasterPos2f(0.0f,0.13f);
		glPrint("%c",rgcnames[inames][2]);
	}
	else if(inewgame==4)
	{
		glRasterPos2f(-0.4f,0.19f);
		glPrint("YOU ARE PLAYING FOR NICKELS.");
		glRasterPos2f(-0.4f,0.16f);
		glPrint("ALL PLAYERS START WITH [$%i.00]",icash);
		glRasterPos2f(-0.4f,0.13f);
		glPrint("USE +/- KEYS, THEN HIT SPACE TO DEAL");
	}
	//lay down four cards
	else if(inewgame>4&&inewgame<9)
	{
		isec2=Time();
		if(isec2-isec>500||(isec2<isec&&1000-isec+isec2>500))
		{
			if(!bflip)
			{
				//PlaySound("cardsound.wav", NULL, SND_ASYNC | SND_LOOP);
				//PlaySound("cardsound.wav", NULL, SND_SYNC);
				PlaySound("Data/cardsound.wav", NULL, SND_ASYNC);
				
				horsedeck.Draw(inewgame-4,0);
				//make sure not the same as previous 1-3 cards
				for(ix=0;ix<inewgame-5;ix++)
				{
					if(horsedeck.Gethandcard(inewgame-4,0).inum==
						horsedeck.Gethandcard(inewgame-(5+ix),0).inum)
					{
						bflip=true;
					}
				}
				if(!bflip)
				{
					rgistorenum[inewgame-5]=horsedeck.Gethandcard(inewgame-4,0).inum;
					inewgame+=1;
				}
			}
			else
			{
				PlaySound("Data/cardsound.wav", NULL, SND_ASYNC);
				horsedeck.Discard(inewgame-4,0);
				bflip=false;
			}
			isec=Time();
		}
	}
	//move the horses
	else if(inewgame>8&&inewgame<13)
	{
		isec2=Time();
		if(isec2-isec>500||(isec2<isec&&1000-isec+isec2>500))
		{
			PlaySound("Data/horsemove.wav", NULL, SND_ASYNC);
			//next line's pretty cool, huh?  got it right on the first try
			racehorses[horsedeck.Gethandcard(inewgame-8,0).inum-2].ispot=4-(inewgame-8);
			inewgame+=1;
			isec=Time();
		}
	}
	//return the four cards to the deck, shuffle
	else if(inewgame==13)
	{
		isec2=Time();
		if(isec2-isec>500||(isec2<isec&&1000-isec+isec2>500))
		{
			PlaySound("Data/cardsound.wav", NULL, SND_ASYNC);
			horsedeck.Fulldiscard();
			PlaySound("Data/shuffle.wav",NULL, SND_ASYNC);
			horsedeck.Shuffle();
			inewgame+=1;
			iguy=iturn;
			isec=Time();
		}
	}
	//deal
	else if(inewgame==14&&horsedeck.Getsize()>0)
	{
		isec2=Time();
		if(isec2-isec>250||(isec2<isec&&1000-isec+isec2>250))
		{
			PlaySound("Data/cardsound.wav",NULL, SND_ASYNC);
			horsedeck.Draw(iguy+5,0);
			iguy+=1;
			if(iguy==iplayers)
				iguy=0;
			isec=Time();
		}
		if(horsedeck.Getsize()==0)
		{
			inewgame+=1;
			iguy=iturn;
			itrash=0;
		}
	}
	//pay up
	else if(inewgame>14&&inewgame<31)
	{
		isec2=Time();
		if(!bplayer&&(isec2-isec>500||(isec2<isec&&1000-isec+isec2>500)))
		{
			if(!bstore)
			{
				for(ix=5;ix<=iplayers+4;ix++)
				{
					for(ij=0;ij<horsedeck.Gethandsize(ix);ij++)
					{
						if(horsedeck.Gethandcard(ix,ij).inum==rgistorenum[itrash])
						{
							rgistorespot[0]=ix;
							rgistorespot[1]=ij;
							if(ix-5<ihuman)
								bplayer=true;
							bstore=true;
							ix=iplayers+5;
							break;
						}
					}
				}
			}
			else
			{
				PlaySound("Data/ching.wav", NULL, SND_ASYNC);
				rginickels[rgistorespot[0]-5]-=(itrash+1);
				ipot+=(itrash+1);
				horsedeck.Handgive(rgistorespot[0],rgistorespot[1],iplayers+5,false);
				bstore=false;
				if(inewgame%4==2&&inewgame>15)
					itrash+=1;
				inewgame+=1;
			}
			isec=Time();
		}
	}
	//take turns rolling dice
	else if(inewgame==31)
	{
		isec2=Time();
		if((isec2-isec>900||(isec2<isec&&1000-isec+isec2>900)))
		{
			if(idice==0)
			{
				if(iguy<ihuman)
				{
					bdice=true;
				}
				idice+=1;
				fxspin=FXSPIN;
				fyspin=FYSPIN;
				fzspin=FZSPIN;
			}
			else if(idice==1&&iguy>=ihuman)	//computer only
			{
				PlaySound("Data/dice.wav", NULL, SND_ASYNC);
				fxspin*=10;
				fyspin*=10;
				fzspin*=10;
				bspin=true;
				idice+=1;
			}
			else if(idice==2&&iguy>=ihuman)
			{
				StopDice();
			}
			else if(idice==3)
			{
				if(irand1+irand2==rgistorenum[0])
					itrash=0;
				else if(irand1+irand2==rgistorenum[1])
					itrash=1;
				else if(irand1+irand2==rgistorenum[2])
					itrash=2;
				else if(irand1+irand2==rgistorenum[3])
					itrash=3;
				else
					itrash=4;
				if(itrash==4)
				{
					PlaySound("Data/horsemove.wav", NULL, SND_ASYNC);
					racehorses[irand1+irand2-2].ispot+=1;
					//do we have a winner?
					ix=racehorses[irand1+irand2-2].ispot;
					switch(ix)
					{
					case 8:
						if(irand1+irand2==2||irand1+irand2==12)
							inewgame+=1;
						break;
					case 9:
						if(irand1+irand2==3||irand1+irand2==11)
							inewgame+=1;
						break;
					case 12:
						if(irand1+irand2==4||irand1+irand2==10)
							inewgame+=1;
						break;
					case 14:
						if(irand1+irand2==5||irand1+irand2==9)
							inewgame+=1;
						break;
					case 16:
						if(irand1+irand2==6||irand1+irand2==8)
							inewgame+=1;
						break;
					case 18:
						if(irand1+irand2==7)
							inewgame+=1;
						break;
					default:
						//uh
						break;
					}
					idice=0;
					iguy+=1;
					if(iguy==iplayers)
						iguy=0;
				}
				else
				{
					rgistorespot[0]=iguy+5;
					bstore=true;
					if(iguy<ihuman)
						bplayer=true;
					else
						idice+=1;
				}
			}
			else if(idice==4)
			{
				PlaySound("Data/ching.wav", NULL, SND_ASYNC);
				rginickels[iguy]-=(itrash+1);
				ipot+=(itrash+1);
				
				bstore=false;
				iguy+=1;
				if(iguy==iplayers)
					iguy=0;
				idice=0;
			}
			isec=Time();
		}
	}
	//clap, kill some time
	else if(inewgame>31&&inewgame<37)
	{
		isec2=Time();
		if(isec2-isec>900||(isec2<isec&&1000-isec+isec2>900))
		{
			if(inewgame==32)
			{
				mciSendString("open Data/winner.MP3 type sequencer",NULL,0,NULL);
				mciSendString("play Data/winner.MP3",NULL,0,NULL);
				bwin=false;
			}
			inewgame+=1;
			isec=Time();
		}
	}
	else if(inewgame>36&&inewgame<41)
	{
		isec2=Time();
		if(!bplayer&&(isec2-isec>500||(isec2<isec&&1000-isec+isec2>500)))
		{
			if(!bwin)
			{
				for(ix=5;ix<=iplayers+4;ix++)
				{
					for(ij=0;ij<horsedeck.Gethandsize(ix);ij++)
					{
						if(horsedeck.Gethandcard(ix,ij).inum==irand1+irand2)
						{
							rgistorespot[0]=ix;
							rgistorespot[1]=ij;
							if(ix-5<ihuman)
								bplayer=true;
							bwin=true;
							ix=iplayers+5;	//break out of the loop
							break;
						}
					}
				}
			}
			else
			{
				PlaySound("Data/ching.wav", NULL, SND_ASYNC);
				rginickels[rgistorespot[0]-5]+=ipot/(41-inewgame);
				ipot-=ipot/(41-inewgame);
				horsedeck.Handgive(rgistorespot[0],rgistorespot[1],iplayers+5,false);
				bwin=false;
				inewgame+=1;
			}
			isec=Time();
		}
	}
	else if(inewgame==41)
	{
		isec2=Time();
		if(isec2-isec>500||(isec2<isec&&1000-isec+isec2>500))
		{
			icash=1;
			bplayer=false;
			bwin=false;
			iguy=0;
			fcardzoom=0.0f;
			fxspin=FXSPIN;
			fyspin=FYSPIN;
			fzspin=FZSPIN;
			iturn+=1;
			if(iturn==iplayers)
				iturn=0;
			horsedeck.Fulldiscard();
			PlaySound("Data/shuffle.wav", NULL, SND_ASYNC);
			for(ix=0;ix<11;ix++)
			{
				racehorses[ix].ispot=4;
			}
			PlaySound("Data/horsemove.wav", NULL, SND_ASYNC);
			inewgame=5;
			isec=Time();
		}
	}
		
	// Pulsing Colors Based On Text Position
	// Position The Text On The Screen
	
	/*********coordinates**********/
	/*glColor3f(0.0f,1.0f,0.0f);
	glRasterPos2f(-0.35f,0.1f);
	glPrint("x_offset= %f", fcardzoom);	// Print GL Text To The Screen
	glRasterPos2f(-0.35f,0.05f);
	glPrint("y_offset= %f", y_offset);	// Print GL Text To The Screen
	glRasterPos2f(-0.35f,0.0f);
	glPrint("z_offset= %f", z_offset);	// Print GL Text To The Screen
	/********************/


	glTranslatef(0.0f,0.0f,1.0f);	//done with text so reset
	/**************/

	glTranslatef(-5.0f,-1.0f,-24.0f);
	glEnable(GL_TEXTURE_2D);
	if(!bdark)
		glColor3f(1.0f,1.0f,1.0f);
	else
		glColor3f(0.0f,0.0f,1.0f);

	glRotatef(xrot,1.0f,0.0f,0.0f);
	glRotatef(yrot,0.0f,1.0f,0.0f);
	glRotatef(zrot,0.0f,0.0f,1.0f);

	glBindTexture(GL_TEXTURE_2D, texture[0]);

	/*******draw gameboard******************/
	glBegin(GL_QUADS);
		// Front Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.6875f, -6.875f,  0.5f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(4.6875f, -6.875f,  0.5f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(4.6875f, 6.875f,  0.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-4.6875f, 6.875f,  0.5f);
		//routed edges
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.6875f, 6.875f,  0.5f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(4.6875f, 6.875f,  0.5f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(4.8125f, 7.0f,  -0.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-4.8125f, 7.0f, -0.5f);

		glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.8125f, -7.0f, -0.5f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-4.6875f, -6.875f, 0.5f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-4.6875f, 6.875f, 0.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-4.8125f, 7.0f, -0.5f);

		glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.8125f, -7.0f, -0.5f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-4.6875f, -6.875f, 0.5f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(4.6875f, -6.875f, 0.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(4.8125f, -7.0f, -0.5f);

		glTexCoord2f(0.0f, 0.0f); glVertex3f(4.6875f, -6.875f, 0.5f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(4.8125f, -7.0f, -0.5f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(4.8125f, 7.0f, -0.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(4.6875f, 6.875f, 0.5f);

		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-4.8125f, 7.0f, -0.5f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.8125f, 7.0f,  0.5f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(4.8125f, 7.0f,  0.5f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(4.8125f, 7.0f, -0.5f);
		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-4.8125f, -7.0f, -0.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(4.8125f, -7.0f, -0.5f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(4.8125f, -7.0f,  0.5f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-4.8125, -7.0f,  0.5f);
		// Right face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(4.8125f, -7.0f, -0.5f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(4.8125f,  7.0f, -0.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(4.8125f,  7.0f,  0.5f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(4.8125f, -7.0f,  0.5f);
		// Left Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.8125f, -7.0f, -0.5f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-4.8125f, -7.0f,  0.5f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-4.8125f,  7.0f,  0.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-4.8125f,  7.0f, -0.5f);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, texture[57]);
	glBegin(GL_QUADS);
		// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-4.8125f, -7.0f, -0.5f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-4.8125f, 7.0f, -0.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(4.8125f, 7.0f, -0.5f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(4.8125f, -7.0f, -0.5f);
	glEnd();

	//draw lines
	glColor3f(1.0f,1.0f,1.0f);
	glBindTexture(GL_TEXTURE_2D, texture[60]);
	glBegin(GL_QUADS);
		//horizontals
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.6875f, 6.0625f,  0.51f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(4.6875f, 6.0625f,  0.51f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(4.6875f, 6.1875f,  0.51f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-4.6875f, 6.1875f,  0.51f);

		glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.6875f, -5.0f,  0.51f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(4.6875f, -5.0f,  0.51f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(4.6875f, -4.875f,  0.51f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-4.6875f, -4.875f,  0.51f);

		glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.6875f, -4.3125f,  0.51f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(4.6875f, -4.3125f,  0.51f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(4.6875f, -4.1875f,  0.51f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-4.6875f, -4.1875f,  0.51f);
		//verticals
		for(fx=.625;fx!=9.625f;fx+=.75)
		{
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-4.8125f+fx, -6.875f,  0.51f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(-4.6875f+fx, -6.875f,  0.51f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(-4.6875f+fx, 6.875f,  0.51f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-4.8125f+fx, 6.875f,  0.51f);
		}
	glEnd();

	//translate away from center of board
	glTranslatef(-3.75f,6.59375f,0.5f);
	glDisable(GL_TEXTURE_2D);
	glColor3f(0.0f,0.0f,0.0f);
	//top row of holes
	for(ix=0;ix<11;ix++)
	{
		gluDisk(quadratic,0.0f,FRADIUS,ISLICE,ISLICE);
		glTranslatef(.75f,0.0f,0.0f);
	}
	glTranslatef(-8.25f,-13.19375f,0.0f);
	for(ix=0;ix<11;ix++)
	{
		gluDisk(quadratic,0.0f,FRADIUS,ISLICE,ISLICE);
		glTranslatef(0.75f,0.0f,0.0f);
	}
	glTranslatef(-8.25f,0.4f,0.0f);
	for(ix=0;ix<11;ix++)
	{
		gluDisk(quadratic,0.0f,FRADIUS,ISLICE,ISLICE);
		glTranslatef(0.75f,0.0f,0.0f);
	}
	glTranslatef(-8.25f,0.4f,0.0f);
	for(ix=0;ix<11;ix++)
	{
		gluDisk(quadratic,0.0f,FRADIUS,ISLICE,ISLICE);
		glTranslatef(0.75f,0.0f,0.0f);
	}
	glTranslatef(-8.25f,0.4f,0.0f);
	for(ix=0;ix<11;ix++)
	{
		gluDisk(quadratic,0.0f,FRADIUS,ISLICE,ISLICE);
		glTranslatef(0.75f,0.0f,0.0f);
	}
	glTranslatef(-8.25f,0.80625f,0.0f);
	for(ix=0;ix<11;ix++)
	{
		gluDisk(quadratic,0.0f,FRADIUS,ISLICE,ISLICE);
		glTranslatef(0.75f,0.0f,0.0f);
	}
	glTranslatef(-8.25f,0.40625f,0.0f);
	for(ij=2;ij<=12;ij++)
	{
		if(ij==2||ij==12)
			itack=3;
		else if(ij==3||ij==11)
			itack=4;
		else if(ij==4||ij==10)
			itack=7;
		else if(ij==5||ij==9)
			itack=9;
		else if(ij==6||ij==8)
			itack=11;
		else if(ij==7)
			itack=13;
		fsparc=10.25f/float(itack+1);
		for(ix=0;ix<itack;ix++)
		{
			glTranslatef(0.0f,fsparc,0.0f);
			gluDisk(quadratic,0.0f,FRADIUS,ISLICE,ISLICE);
		}
		glTranslatef(0.75f,-10.25f+fsparc,0.0f);
	}
	glTranslatef(-8.5625f,0.0f,0.0f);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture[53]);
	fsparc=0.125f;
	fsparc2=0.1875f;
	//draw numbers
	glColor3f(0.0f,0.0f,1.0f);
	for(ix=0;ix<8;ix++)
	{
		if(!bdark)
			glColor3f(racehorses[ix].rgfcolor[0],racehorses[ix].rgfcolor[1],racehorses[ix].rgfcolor[2]);
		glBegin(GL_QUADS);
			glTexCoord2f(fsparc, 0.875f); glVertex3f(0.0f, 0.0f,  0.01f);
			glTexCoord2f(fsparc2, 0.875f); glVertex3f(0.625f, 0.0f,  0.01f);
			glTexCoord2f(fsparc2, 0.9375f); glVertex3f(0.625f, 0.625f,  0.01f);
			glTexCoord2f(fsparc, 0.9375f); glVertex3f(0.0f, 0.625f,  0.01f);
		glEnd();
		glTranslatef(0.75f,0.0f,0.0f);
		fsparc+=0.0625f;
		fsparc2+=0.0625f;
	}
	if(!bdark)
		glColor3f(racehorses[8].rgfcolor[0],racehorses[8].rgfcolor[1],racehorses[8].rgfcolor[2]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0625f, 0.875f); glVertex3f(0.0f, 0.0f,  0.01f);
		glTexCoord2f(0.125f, 0.875f); glVertex3f(0.3125f, 0.0f,  0.01f);
		glTexCoord2f(0.125f, 0.9375f); glVertex3f(0.3125f, 0.625f,  0.01f);
		glTexCoord2f(0.0625f, 0.9375f); glVertex3f(0.0f, 0.625f,  0.01f);

		glTexCoord2f(0.0f, 0.875f); glVertex3f(0.3125f, 0.0f,  0.01f);
		glTexCoord2f(0.0625f, 0.875f); glVertex3f(0.625f, 0.0f,  0.01f);
		glTexCoord2f(0.0625f, 0.9375f); glVertex3f(0.625f, 0.625f,  0.01f);
		glTexCoord2f(0.0f, 0.9375f); glVertex3f(0.3125f, 0.625f,  0.01f);
	glEnd();
	glTranslatef(0.75f,0.0f,0.0f);
	if(!bdark)
		glColor3f(racehorses[9].rgfcolor[0],racehorses[9].rgfcolor[1],racehorses[9].rgfcolor[2]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0625f, 0.875f); glVertex3f(0.0f, 0.0f,  0.01f);
		glTexCoord2f(0.125f, 0.875f); glVertex3f(0.3125f, 0.0f,  0.01f);
		glTexCoord2f(0.125f, 0.9375f); glVertex3f(0.3125f, 0.625f,  0.01f);
		glTexCoord2f(0.0625f, 0.9375f); glVertex3f(0.0f, 0.625f,  0.01f);

		glTexCoord2f(0.0625f, 0.875f); glVertex3f(0.3125f, 0.0f,  0.01f);
		glTexCoord2f(0.125f, 0.875f); glVertex3f(0.625f, 0.0f,  0.01f);
		glTexCoord2f(0.125f, 0.9375f); glVertex3f(0.625f, 0.625f,  0.01f);
		glTexCoord2f(0.0625f, 0.9375f); glVertex3f(0.3125f, 0.625f,  0.01f);
	glEnd();
	glTranslatef(0.75f,0.0f,0.0f);
	if(!bdark)
		glColor3f(racehorses[10].rgfcolor[0],racehorses[10].rgfcolor[1],racehorses[10].rgfcolor[2]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0625f, 0.875f); glVertex3f(0.0f, 0.0f,  0.01f);
		glTexCoord2f(0.125f, 0.875f); glVertex3f(0.3125f, 0.0f,  0.01f);
		glTexCoord2f(0.125f, 0.9375f); glVertex3f(0.3125f, 0.625f,  0.01f);
		glTexCoord2f(0.0625f, 0.9375f); glVertex3f(0.0f, 0.625f,  0.01f);

		glTexCoord2f(0.125f, 0.875f); glVertex3f(0.3125f, 0.0f,  0.01f);
		glTexCoord2f(0.1875f, 0.875f); glVertex3f(0.625f, 0.0f,  0.01f);
		glTexCoord2f(0.1875f, 0.9375f); glVertex3f(0.625f, 0.625f,  0.01f);
		glTexCoord2f(0.125f, 0.9375f); glVertex3f(0.3125f, 0.625f,  0.01f);
	glEnd();

	//draw horses
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture[58]);
	glTranslatef(-7.1875f,-0.40625f,0.0f);
	
	for(ix=0;ix<11;ix++)
	{
		if(!bdark)
			glColor3f(racehorses[ix].rgfcolor[0],racehorses[ix].rgfcolor[1],racehorses[ix].rgfcolor[2]);
		else
			glColor3f(0.0f,0.0f,1.0f);

		fsparc=0;
		if(inewgame>31&&ix==irand1+irand2-2)
			fsparc+=11.1875;
		else if(racehorses[ix].ispot==0)
			fsparc=-2.00625f;
		else if(racehorses[ix].ispot==1)
			fsparc=-1.60625f;
		else if(racehorses[ix].ispot==2)
			fsparc=-1.20625f;
		else if(racehorses[ix].ispot==3)
			fsparc=-0.80625f;
		else
		{
			if(ix==0||ix==10)
				fsparc=2.5625f*(racehorses[ix].ispot-4);
			else if(ix==1||ix==9)
				fsparc=2.05f*(racehorses[ix].ispot-4);
			else if(ix==2||ix==8)
				fsparc=1.28125f*(racehorses[ix].ispot-4);
			else if(ix==3||ix==7)
				fsparc=1.025f*(racehorses[ix].ispot-4);
			else if(ix==4||ix==6)
				fsparc=0.8541666667f*(racehorses[ix].ispot-4);
			else
				fsparc=0.7321428571f*(racehorses[ix].ispot-4);
			if(fsparc!=0.0f)
				fsparc+=0.40625f;
		}
		glTranslatef(0.0f,fsparc,0.0f);
		gluCylinder(quadratic,FRADIUS,FRADIUS,FHEIGHT,ISLICE,ISLICE);	// Draw Cylinder
		glTranslatef(0.0f,0.0f,FHEIGHT);
		gluCylinder(quadratic,FRADIUS,3*FRADIUS,2*FRADIUS,ISLICE,ISLICE);	// Draw cone
		glTranslatef(0.0f,0.0f,2*FRADIUS);
		gluDisk(quadratic,0.0f,3*FRADIUS,ISLICE,ISLICE);
		glTranslatef(0.75f,-1*fsparc,-1*FHEIGHT-2*FRADIUS);
	}
	/**********end gameboard**********************/
	glLoadIdentity();									// Reset The View

	//draw pointer
	glEnable(GL_BLEND);									// Enable Blending
	glDisable(GL_DEPTH_TEST);							// Disable Depth Testing

	glColor3f(1.0f,1.0f,1.0f);
	glEnable(GL_TEXTURE_2D);
	glBlendFunc(GL_DST_COLOR,GL_ZERO);				// Blend Screen Color With Zero (Black)
	glBindTexture(GL_TEXTURE_2D, texture[54]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(float(x_offset), float(y_offset)-0.005f, -0.1f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(float(x_offset)+0.005f, float(y_offset)-0.005f, -0.1f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(float(x_offset)+0.005f, float(y_offset), -0.1f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(float(x_offset), float(y_offset), -0.1f);
	glEnd();
	glBlendFunc(GL_ONE, GL_ONE);					// Copy Image 2 Color To The Screen
	glBindTexture(GL_TEXTURE_2D, texture[55]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(float(x_offset), float(y_offset)-0.005f, -0.1f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(float(x_offset)+0.005f, float(y_offset)-0.005f, -0.1f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(float(x_offset)+0.005f, float(y_offset), -0.1f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(float(x_offset), float(y_offset), -0.1f);
	glEnd();

	glEnable(GL_DEPTH_TEST);							// Enable Depth Testing
	glDisable(GL_BLEND);								// Disable Blending
	//end pointer

	glLoadIdentity();									// Reset The View

	/********draw dice**************/
	glColor3f(0.0f,1.0f,0.0f);
	glTranslatef(1.2f,-4.0f,-13.0f);
	//draw two dice
	glRotatef(diexrot,1.0f,0.0f,0.0f);
	glRotatef(dieyrot,0.0f,1.0f,0.0f);
	glRotatef(diezrot,0.0f,0.0f,1.0f);
	for(ix=0;ix<2;ix++)
	{
	//draw front face (one)
	glBindTexture(GL_TEXTURE_2D, texture[62]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.125f, -0.125f,  0.125f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(0.125f, -0.125f,  0.125f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(0.125f, 0.125f,  0.125f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.125f, 0.125f,  0.125f);
	glEnd();
	//draw left face (two)
	glBindTexture(GL_TEXTURE_2D, texture[63]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.125f, -0.125f, -0.125f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.125f, -0.125f, 0.125f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.125f, 0.125f, 0.125f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.125f, 0.125f, -0.125f);
	glEnd();
	//draw top (three)
	glBindTexture(GL_TEXTURE_2D, texture[64]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.125f, 0.125f, 0.125f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(0.125f, 0.125f, 0.125f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(0.125f, 0.125f, -0.125f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.125f, 0.125f, -0.125f);
	glEnd();
	//draw bottom (four)
	glBindTexture(GL_TEXTURE_2D, texture[65]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.125f, -0.125f, 0.125f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(0.125f, -0.125f, 0.125f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(0.125f, -0.125f, -0.125f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.125f, -0.125f, -0.125f);
	glEnd();
	//draw right face (five)
	glBindTexture(GL_TEXTURE_2D, texture[66]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.125f, -0.125f, 0.125f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(0.125f, -0.125f, -0.125f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(0.125f, 0.125f, -0.125f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.125f, 0.125f, 0.125f);
	glEnd();
	//draw back face (six)
	glBindTexture(GL_TEXTURE_2D, texture[67]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.125f, -0.125f, -0.125f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(0.125f, -0.125f, -0.125f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(0.125f, 0.125f, -0.125f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.125f, 0.125f, -0.125f);
	glEnd();

	glLoadIdentity();
	glTranslatef(1.8f,-3.8f,-13.0f);
	glRotatef(dieyrot2,1.0f,0.0f,0.0f);
	glRotatef(diezrot2,0.0f,1.0f,0.0f);
	glRotatef(diexrot2,0.0f,0.0f,1.0f);
	glColor3f(1.0f,0.0f,0.0f);
	}

	/*******************************/
	glLoadIdentity();									// Reset The View

	glTranslatef(-1.4f,2.7f,-10.0f);
	glBindTexture(GL_TEXTURE_2D, texture[57]);
	//glRotatef(xrot,1.0f,0.0f,0.0f);
	//glRotatef(yrot,0.0f,1.0f,0.0f);
	//glRotatef(zrot,0.0f,0.0f,1.0f);

	glColor3f(1.0f,1.0f,1.0f);
	glRotatef(30.0f,1.0f,0.0f,0.0f);
	glRotatef(-25.0f,0.0f,1.0f,0.0f);
	//draw deck of cards
	itack=horsedeck.Getsize();
	for(ix=0;ix<itack;ix++)
	{
		glRotatef(-85.0f,1.0f,0.0f,0.0f);
		glBindTexture(GL_TEXTURE_2D, texture[57]);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.6f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.6f, 1.0f,  0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f,  0.0f);
		glEnd();
		glBindTexture(GL_TEXTURE_2D, texture[59]);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f,  -0.005f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.6f, 0.0f,  -0.005f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.6f, 0.0f,  0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.0f,  0.0f);
		glEnd();
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(0.6f, 0.0f, 0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.6f, 0.0f, -0.005f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.6f, 1.0f, -0.005f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(0.6f, 1.0f, 0.0f);
		glEnd();
		glRotatef(85.0f,1.0f,0.0f,0.0f);
		glTranslatef(0.0f,0.005f,0.0f);
	}
	glLoadIdentity();									// Reset The View

	if(bdark)
		glColor3f(0.0f,0.0f,1.0f);
	glTranslatef(-3.9f,-1.3f,-10.0f);
	if(horsedeck.Gethandsize(1)>0)
	{
		LoadCard(horsedeck.Gethandcard(1,0));
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.6f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.6f, 1.0f,  0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f,  0.0f);
		glEnd();
	}
	glTranslatef(1.0f,0.0f,0.0f);
	if(horsedeck.Gethandsize(2)>0)
	{
		LoadCard(horsedeck.Gethandcard(2,0));
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.6f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.6f, 1.0f,  0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f,  0.0f);
		glEnd();
	}
	glTranslatef(1.0f,0.0f,0.0f);
	if(horsedeck.Gethandsize(3)>0)
	{
		LoadCard(horsedeck.Gethandcard(3,0));
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.6f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.6f, 1.0f,  0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f,  0.0f);
		glEnd();
	}
	glTranslatef(1.0f,0.0f,0.0f);
	if(horsedeck.Gethandsize(4)>0)
	{
		LoadCard(horsedeck.Gethandcard(4,0));
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.6f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.6f, 1.0f,  0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f,  0.0f);
		glEnd();
	}
	glTranslatef(1.3f-(fcardzoom/2.6f),3.2f-fcardzoom/7.0f,fcardzoom);
	for(ix=1;ix<iplayers+1;ix++)
	{
		for(ij=0;ij<horsedeck.Gethandsize(ix+4);ij++)
		{
			LoadCard(horsedeck.Gethandcard(ix+4,ij));
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f,  0.0f);
				glTexCoord2f(1.0f, 0.0f); glVertex3f(0.4f, 0.0f,  0.0f);
				glTexCoord2f(1.0f, 1.0f); glVertex3f(0.4f, 0.6666666667f,  0.0f);
				glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.6666666667f,  0.0f);
			glEnd();
			glTranslatef(0.09f,0.0f,0.0f);
		}
		//fsparc gets rid of the offset caused by all the cards in a hand
		fsparc=-1*(float(ij)*0.09f);
		glTranslatef(fsparc,-1.0f+fcardzoom/19.0f,0.0f);
		if(ix%5==0)
		{
			glTranslatef(1.2f,-5.0f*(-1.0f+fcardzoom/19.0f),0.0f);
		}
	}

	glLoadIdentity();
	glTranslatef(-2.0f,2.7f,-10.0f);
	for(ij=0;ij<horsedeck.Gethandsize(iplayers+5);ij++)
	{
		LoadCard(horsedeck.Gethandcard(iplayers+5,ij));
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(0.4f, 0.0f,  0.0f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(0.4f, 0.6666666667f,  0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.6666666667f,  0.0f);
		glEnd();
		glTranslatef(0.09f,0.0f,0.0f);
	}
	diexrot+=fxspin;
	dieyrot+=fyspin;
	diezrot+=fzspin;
	diexrot2+=fxspin;
	dieyrot2+=fyspin;
	diezrot2+=fzspin;
	}	//end giant else

	glLoadIdentity();
	return TRUE;										// Keep Going
}

GLvoid KillGLWindow(GLvoid)								// Properly Kill The Window
{
	if (fullscreen)										// Are We In Fullscreen Mode?
	{
		ChangeDisplaySettings(NULL,0);					// If So Switch Back To The Desktop
		ShowCursor(FALSE);								// Show Mouse Pointer
	}

	if (hRC)											// Do We Have A Rendering Context?
	{
		if (!wglMakeCurrent(NULL,NULL))					// Are We Able To Release The DC And RC Contexts?
		{
			MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		}

		if (!wglDeleteContext(hRC))						// Are We Able To Delete The RC?
		{
			MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		}
		hRC=NULL;										// Set RC To NULL
	}

	if (hDC && !ReleaseDC(hWnd,hDC))					// Are We Able To Release The DC
	{
		MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		hDC=NULL;										// Set DC To NULL
	}

	if (hWnd && !DestroyWindow(hWnd))					// Are We Able To Destroy The Window?
	{
		MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		hWnd=NULL;										// Set hWnd To NULL
	}

	if (!UnregisterClass("OpenGL",hInstance))			// Are We Able To Unregister Class
	{
		MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		hInstance=NULL;									// Set hInstance To NULL
	}
	KillFont();
}

/*	This Code Creates Our OpenGL Window.  Parameters Are:					*
 *	title			- Title To Appear At The Top Of The Window				*
 *	width			- Width Of The GL Window Or Fullscreen Mode				*
 *	height			- Height Of The GL Window Or Fullscreen Mode			*
 *	bits			- Number Of Bits To Use For Color (8/16/24/32)			*
 *	fullscreenflag	- Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)	*/
 
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
	GLuint		PixelFormat;			// Holds The Results After Searching For A Match
	WNDCLASS	wc;						// Windows Class Structure
	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left=(long)0;			// Set Left Value To 0
	WindowRect.right=(long)width;		// Set Right Value To Requested Width
	WindowRect.top=(long)0;				// Set Top Value To 0
	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height

	fullscreen=fullscreenflag;			// Set The Global Fullscreen Flag

	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages
	wc.cbClsExtra		= 0;									// No Extra Window Data
	wc.cbWndExtra		= 0;									// No Extra Window Data
	wc.hInstance		= hInstance;							// Set The Instance
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
	//wc.hCursor			= NULL;
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground	= NULL;									// No Background Required For GL
	wc.lpszMenuName		= NULL;									// We Don't Want A Menu
	wc.lpszClassName	= "OpenGL";								// Set The Class Name

	if (!RegisterClass(&wc))									// Attempt To Register The Window Class
	{
		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;											// Return FALSE
	}
	
	if (fullscreen)												// Attempt Fullscreen Mode?
	{
		DEVMODE dmScreenSettings;								// Device Mode
		memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
		dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
		dmScreenSettings.dmPelsWidth	= width;				// Selected Screen Width
		dmScreenSettings.dmPelsHeight	= height;				// Selected Screen Height
		dmScreenSettings.dmBitsPerPel	= bits;					// Selected Bits Per Pixel
		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
		if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			// If The Mode Fails, Offer Two Options.  Quit Or Use Windowed Mode.
			if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
			{
				fullscreen=FALSE;		// Windowed Mode Selected.  Fullscreen = FALSE
			}
			else
			{
				// Pop Up A Message Box Letting User Know The Program Is Closing.
				MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
				return FALSE;									// Return FALSE
			}
		}
	}

	if (fullscreen)												// Are We Still In Fullscreen Mode?
	{
		dwExStyle=WS_EX_APPWINDOW;								// Window Extended Style
		dwStyle=WS_POPUP;										// Windows Style
		ShowCursor(FALSE);										// Hide Mouse Pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style
		ShowCursor(FALSE);
	}

	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);		// Adjust Window To True Requested Size

	// Create The Window
	if (!(hWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
								"OpenGL",							// Class Name
								title,								// Window Title
								dwStyle |							// Defined Window Style
								WS_CLIPSIBLINGS |					// Required Window Style
								WS_CLIPCHILDREN,					// Required Window Style
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								hInstance,							// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
		1,											// Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
		PFD_TYPE_RGBA,								// Request An RGBA Format
		bits,										// Select Our Color Depth
		0, 0, 0, 0, 0, 0,							// Color Bits Ignored
		0,											// No Alpha Buffer
		0,											// Shift Bit Ignored
		0,											// No Accumulation Buffer
		0, 0, 0, 0,									// Accumulation Bits Ignored
		16,											// 16Bit Z-Buffer (Depth Buffer)  
		0,											// No Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	};
	
	if (!(hDC=GetDC(hWnd)))							// Did We Get A Device Context?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!SetPixelFormat(hDC,PixelFormat,&pfd))		// Are We Able To Set The Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if (!(hRC=wglCreateContext(hDC)))				// Are We Able To Get A Rendering Context?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!wglMakeCurrent(hDC,hRC))					// Try To Activate The Rendering Context
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	ShowWindow(hWnd,SW_SHOW);						// Show The Window
	SetForegroundWindow(hWnd);						// Slightly Higher Priority
	SetFocus(hWnd);									// Sets Keyboard Focus To The Window
	ReSizeGLScene(width, height);					// Set Up Our Perspective GL Screen

	if (!InitGL())									// Initialize Our Newly Created GL Window
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	return TRUE;									// Success
}

LRESULT CALLBACK WndProc(	HWND	hWnd,			// Handle For This Window
							UINT	uMsg,			// Message For This Window
							WPARAM	wParam,			// Additional Message Information
							LPARAM	lParam)			// Additional Message Information
{
	switch (uMsg)									// Check For Windows Messages
	{
		/****mouse stuff from Smart Idiot's 3D dragging demo*******/
		case WM_LBUTTONDOWN: // If the mouse was clicked:
		{
			if(x_offset>-0.040774f&&x_offset<-0.033655f&&
				y_offset>0.029879f&&y_offset<0.032145f)
			{
				Falsify();
				PlaySound("Data/clickerx.wav", NULL, SND_ASYNC);
				bmenu=true;
				bdark=true;
			}
			else if(x_offset>-0.030203f&&x_offset<-0.022652f&&
				y_offset>0.029772f&&y_offset<0.032145f)
			{
				Falsify();
				PlaySound("Data/clickerx.wav", NULL, SND_ASYNC);
				bstats=true;
				bdark=true;
			}
			else if(x_offset>0.007874f&&x_offset<0.015102f&&
				y_offset>-0.031928f&&y_offset<-0.027614f&&bdice
				&&!bspin)
			{
				PlaySound("Data/dice.wav", NULL, SND_ASYNC);
				fxspin*=10;
				fyspin*=10;
				fzspin*=10;
				bspin=true;
			}
			else if(x_offset>0.021466f&&x_offset<0.025565f&&
				y_offset>-0.029987f&&y_offset<-0.027722f&&
				bplayer==true)
			{
				PlaySound("Data/clickerx.wav", NULL, SND_SYNC);
				if(inewgame==31)
					idice=4;
				bplayer=false;
			}
			return 0;
        }
		case WM_LBUTTONUP:
		{
			if(bspin&&bdice)
			{
				if(inewgame<31)
				{
					PlaySound("Data/dice2.wav", NULL, SND_ASYNC);
					fxspin=FXSPIN;
					fyspin=FYSPIN;
					fzspin=FZSPIN;
				}
				else
				{
					idice=2;
					bdice=false;
					StopDice();
				}
				bspin=false;
			}
			return 0;
		}
		case WM_RBUTTONDOWN: // If the mouse was clicked:
		{
			bnickel=true;
			return 0;
		}
		case WM_RBUTTONUP:
		{
			bnickel=false;
			return 0;
		}
		case WM_MOUSEMOVE: // The mouse is moving, calculate the offset.
        {
			GLdouble modelMatrix[16]; // The model matrix.
			GLdouble projMatrix[16];  // The projection matrix.
			GLfloat  depth=0.0f;      // The depth into the screen (Not in world units)
			GLint viewport[4];        // The viewport.                
                
			glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); // Load the matricies and the viewport.
			glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
			glGetIntegerv(GL_VIEWPORT, viewport);
                
			//glReadPixels(LOWORD(lParam), viewport[3]-HIWORD(lParam),1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&depth); // Find out how far into the screen stuff is.
                
			gluUnProject(LOWORD(lParam), viewport[3]-HIWORD(lParam),(depth==1.0?distance:depth), modelMatrix, projMatrix, viewport, &x_offset, &y_offset, &z_offset);
			
			return 0;
        }
		/*******************************************/
		case WM_ACTIVATE:							// Watch For Window Activate Message
		{
			if (!HIWORD(wParam))					// Check Minimization State
			{
				active=TRUE;						// Program Is Active
			}
			else
			{
				active=FALSE;						// Program Is No Longer Active
			}

			return 0;								// Return To The Message Loop
		}

		case WM_SYSCOMMAND:							// Intercept System Commands
		{
			switch (wParam)							// Check System Calls
			{
				case SC_SCREENSAVE:					// Screensaver Trying To Start?
				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
				return 0;							// Prevent From Happening
			}
			break;									// Exit
		}

		case WM_CLOSE:								// Did We Receive A Close Message?
		{
			PostQuitMessage(0);						// Send A Quit Message
			return 0;								// Jump Back
		}

		case WM_KEYDOWN:							// Is A Key Being Held Down?
		{
			keys[wParam] = TRUE;					// If So, Mark It As TRUE
			return 0;								// Jump Back
		}

		case WM_KEYUP:								// Has A Key Been Released?
		{
			keys[wParam] = FALSE;					// If So, Mark It As FALSE
			return 0;								// Jump Back
		}

		case WM_SIZE:								// Resize The OpenGL Window
		{
			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
			return 0;								// Jump Back
		}
	}

	// Pass All Unhandled Messages To DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
					HINSTANCE	hPrevInstance,		// Previous Instance
					LPSTR		lpCmdLine,			// Command Line Parameters
					int			nCmdShow)			// Window Show State
{
	MSG		msg;									// Windows Message Structure
	BOOL	done=FALSE;								// Bool Variable To Exit Loop
	
	// Ask The User Which Screen Mode They Prefer
	if (MessageBox(NULL,"Start In Fullscreen Mode? 1024x768", "FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
		fullscreen=FALSE;							// Windowed Mode
	}

	// Create Our OpenGL Window
	if (!CreateGLWindow("HORSE RACE GAME",1024,768,32,fullscreen))
	{
		return 0;									// Quit If Window Was Not Created
	}

	//initialize horses, names, cards
	srand(Time());
	for(ix=0;ix<11;ix++)
	{
		racehorses[ix].ispot=4;
	}
	RandomHorse();
	horsedeck.Sizeit(1);
	ResetNames();
	
	mciSendString("open Data/e.MP3 type sequencer",NULL,0,NULL);
	mciSendString("play Data/e.MP3",NULL,0,NULL);

	while(!done)									// Loop That Runs While done=FALSE
	{
		if(bdone)
			done=true;
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
			if(iintro==0)
			{
				isec=Time();
				iintro+=1;
			}
			if ((active && !DrawGLScene()))// || keys[VK_F5])	// Active?  Was There A Quit Received?
			{
				done=TRUE;							// ESC or DrawGLScene Signalled A Quit
			}
			else									// Not Time To Quit, Update Screen
			{
				SwapBuffers(hDC);					// Swap Buffers (Double Buffering)
			}

			if (keys[VK_F1])						// Is F1 Being Pressed?
			{
				keys[VK_F1]=FALSE;					// If So Make Key FALSE
				KillGLWindow();						// Kill Our Current Window
				fullscreen=!fullscreen;				// Toggle Fullscreen / Windowed Mode
				// Recreate Our OpenGL Window
				if (!CreateGLWindow("HORSE RACE GAME",1024,768,32,fullscreen))
				{
					return 0;						// Quit If Window Was Not Created
				}
			}
			if(keys[VK_DOWN])
			{
				xrot+=0.5f;
			}
			else if(keys[VK_UP])
			{
				xrot-=0.5f;
			}
			if(keys[VK_LEFT])
			{
				yrot-=0.5f;
			}
			else if(keys[VK_RIGHT])
			{
				yrot+=0.5f;
			}
			if(keys[VK_DELETE])
			{
				zrot+=0.5f;
			}
			else if(keys[IPGDN])
			{
				zrot-=0.5f;
			}
			if(keys[VK_SPACE]&&!bspace&&iintro==IINTRO)
			{
				if(inewgame==0)
				{
					Falsify();
					inames=0;
					iinitial=0;
					inewgame+=1;
				}
				else if(bmenu||bstats||ifaq!=0||breset)
				{
					//game is paused
					PlaySound("Data/nope.wav", NULL, SND_ASYNC);
				}
				else if(inewgame==2&&ihuman==0)
				{
					horsedeck.Handgen(iplayers+5);
					inewgame+=2;
				}
				else if(inewgame==3)
				{
					iinitial+=1;
					if(iinitial==3)
					{
						iinitial=0;
						inames+=1;
						if(inames>=ihuman)
							inewgame+=1;
						horsedeck.Handgen(iplayers+5);
					}
				}
				else if(inewgame==4)
				{
					Falsify();
					for(ix=0;ix<iplayers;ix++)
						rginickels[ix]=20*icash;
					ctrash='1';
					for(ix=ihuman;ix<iplayers;ix++)
					{
						rgcnames[ix][0]='C';
						rgcnames[ix][1]='M';
						rgcnames[ix][2]=ctrash;
						ctrash+=1;
						if(ctrash=='9'+1)
							ctrash='A';
					}
					isec=Time();
					PlaySound("Data/shuffle.wav", NULL, SND_ASYNC);
					horsedeck.Shuffle();
					bready=false;
					bdice=false;
					irand1=0;
					irand2=0;
					inewgame+=1;
				}
				else if(bready)
				{
					inewgame+=1;
				}
				bspace=true;
			}
			else if(bspace&&!keys[VK_SPACE])
			{
				bspace=false;
			}
			else if(keys[VK_ESCAPE])
			{
				Falsify();
			}
			else if(keys[IPLUS]&&inewgame>0&&!bplus)
			{
				if(inewgame==1&&iplayers<20)
					iplayers+=1;
				else if(inewgame==2&&ihuman<iplayers)
					ihuman+=1;
				else if(inewgame==3&&rgcnames[inames][iinitial]<'Z')
					rgcnames[inames][iinitial]+=1;
				else if(inewgame==4&&icash<5)
					icash+=1;
				bplus=true;
			}
			else if(keys[IMINUS]&&inewgame>0&&!bminus)
			{
				if(inewgame==1&&iplayers>6)
					iplayers-=1;
				else if(inewgame==2&&ihuman>0)
					ihuman-=1;
				else if(inewgame==3&&rgcnames[inames][iinitial]>'A')
					rgcnames[inames][iinitial]-=1;
				else if(inewgame==4&&icash>1)
					icash-=1;
				bminus=true;
			}
			else if(bplus&&!keys[IPLUS])
			{
				bplus=false;
			}
			else if(bminus&&!keys[IMINUS])
			{
				bminus=false;
			}
			else if(keys[VK_F9])
			{
				RandomHorse();
			}
			else if(keys[VK_F12]&&!bF12)
			{
				if(!breset&&horsedeck.Getsize()!=44)
				{
					Falsify();
					breset=true;
					bdark=true;
					bdice=true;
				}
				else if(horsedeck.Getsize()!=44)
				{
					Falsify();
					icash=1;
					iplayers=6;
					ihuman=1;
					idice=0;
					iturn=0;
					bplayer=false;
					bstore=false;
					bwin=false;
					fcardzoom=0.0f;
					iguy=0;
					ResetNames();
					inewgame=0;
					ipot=0;
					fxspin=FXSPIN;
					fyspin=FYSPIN;
					fzspin=FZSPIN;
					horsedeck.Fulldiscard();
					//PlaySound("shuffle.wav", NULL, SND_ASYNC);
					for(ix=0;ix<11;ix++)
					{
						racehorses[ix].ispot=4;
					}
					PlaySound("Data/horsemove.wav", NULL, SND_ASYNC);
				}
				bF12=true;
			}
			else if(bF12&&!keys[VK_F12])
			{
				bF12=false;
			}
			else if(keys[VK_F11]&&!bF11)
			{
				if(inewgame==0)
				{
					horsedeck.Shuffle();
					PlaySound("Data/shuffle.wav", NULL, SND_ASYNC);
					bF11=true;
				}
			}
			else if(bF11&&!keys[VK_F11])
			{
				bF11=false;
			}
			else if(keys[VK_F5]&&icredits==ICREDITS)
			{
				PlaySound("Data/credits.wav", NULL, SND_ASYNC | SND_LOOP);
				//PlaySound("credits.wav", NULL, SND_ASYNC);
				//mciSendString("open credits.MP3 type sequencer",NULL,0,NULL);
				//mciSendString("play credits.MP3",NULL,0,NULL);
				fcredits=FCREDITS;
				icredits=0;
				bF5=true;
			}
			else if(bF5&&!keys[VK_F5])
			{
				bF5=false;
			}
			else if(keys[VK_F8]&&!bF8)
			{
				bturbo=!bturbo;
				bF8=true;
			}
			else if(bF8&&!keys[VK_F8])
			{
				bF8=false;
			}
			else if(keys[VK_F6]&&!bF6)
			{
				if(ifaq==0)
					Falsify();
				ifaq+=1;
				if(ifaq==3)
					ifaq=0;
				bF6=true;
			}
			else if(bF6&&!keys[VK_F6])
			{
				bF6=false;
			}
			else if(keys[VK_F3]&&fcardzoom<5.0f&&inewgame>=13)
			{
				fcardzoom+=0.025f;
			}
			//this is very strange, sometimes fcardzoom ==0.0 but it breaks
			//through this statement and ends up at -0.025, must be round-off error
			//or something
			else if(keys[VK_F4]&&fcardzoom>0.0f&&inewgame>=13)
			{
				fcardzoom-=0.025f;
				if(fcardzoom<0.0f)
					fcardzoom=0.0f;
			}
		}
	}

	// Shutdown
	KillGLWindow();									// Kill The Window
	return (msg.wParam);							// Exit The Program
}